package org.example.compent;

import cn.hutool.json.JSONObject;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import org.example.util.PDFUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class CmpComponent {

    @Resource
    private FlowExecutor flowExecutor;

    @PostMapping ("/a")
    public void testConfig(@RequestBody JSONObject jsonObject){
        boolean f = jsonObject.getBool("f");
        boolean i = jsonObject.getBool("i");
        boolean k = jsonObject.getBool("k");
        String type = jsonObject.getStr("type");
        DefaultContext context = new DefaultContext();
        context.setData("type", type);
        context.setData("f", f);
        context.setData("i", i);
        context.setData("k", k);
        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", context);
    }

    @GetMapping("/b")
    public void testFor(@RequestParam int count){
        DefaultContext context = new DefaultContext();
        context.setData("count", count);
        LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", context);
    }

    @PostMapping("/liteFlowConfig")
    public void testFor(@RequestBody JSONObject jsonObject){
        boolean flag = jsonObject.getBool("flag");
        int count = jsonObject.getInt("count");
        boolean condition1 = jsonObject.getBool("condition1");
        boolean condition2 = jsonObject.getBool("condition2");
        DefaultContext context = new DefaultContext();
        context.setData("count", count);
        context.setData("flag", flag);
        context.setData("condition1", condition1);
        context.setData("condition2", condition2);
        LiteflowResponse response = flowExecutor.execute2Resp("chainConfig", "arg", context);
    }

    @PostMapping("/liteFlowVariable")
    public void liteFlowVariable(@RequestBody JSONObject jsonObject){
        String type = jsonObject.getStr("type");
        DefaultContext context = new DefaultContext();
        context.setData("type", type);
        LiteflowResponse response = flowExecutor.execute2Resp("chainConfig3", "arg", context);
    }

    @GetMapping("/exportPdf")
    public void export(){
        PDFUtil.exportHtmlToPdf();
    }
}
